*
* Purpose:
* 	Identify applicants with justified envy
*
* Authors:
*	Sandor Sovago
*
* Last update:
*	Sept 18, 2022
*

bys applicant_id: egen rank_of_admission = max((admitted == 1)*rank)
gen rejected = rank_of_admission == 0 | rank < rank_of_admission
gen rejected_above_ps_cutoff = priority_score >= priority_score_cutoff & rejected == 1
bys applicant_id: egen has_justified_envy = max(rejected_above_ps_cutoff)
drop rejected_above_ps_cutoff rank_of_admission
lab var has_justified_envy "Has justified envy"
count if rank == 1 & has_justified_envy == 1
